package com.wsj.a.collapsingdemo.widget.recycler.recycler;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wsj.a.collapsingdemo.R;


public class LoadingMoreView extends LinearLayout {

    public final static int STATUS_LOADING = 0;
    public final static int STATUS_INIT = 1;
    public final static int STATUS_NO_MORE = 2;
    public final static int STATUS_BOTTOM_TEXT=3;
    private TextView mText;


    public LoadingMoreView(Context context) {
        super(context);
        initView(context);
    }

    /**
     * @param context
     * @param attrs
     */
    public LoadingMoreView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public void initView(Context context) {
        //设置内容居中
        setGravity(Gravity.CENTER);
        //设置布局的属性,
        LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.setMargins(0, 26, 0, 26);
        setLayoutParams(lp);
        //加载的字体
        mText = new TextView(getContext());
        mText.setTextColor(ContextCompat.getColor(context, R.color.color_gray_999999));
        mText.setText("正在加载...");
        //
        LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(16, 0, 0, 0);

        mText.setLayoutParams(layoutParams);
        addView(mText);

        setStatus(STATUS_INIT);
    }

    public void setStatus(int status) {
        switch (status) {
            case STATUS_LOADING:
                mText.setText("上拉加载更多");
                this.setVisibility(View.VISIBLE);
                break;
            case STATUS_INIT:
                mText.setText("正在加载...");
                this.setVisibility(View.VISIBLE);
                break;
            case STATUS_NO_MORE:
                mText.setText("没有更多数据了");
                this.setVisibility(View.VISIBLE);
                break;
            case STATUS_BOTTOM_TEXT:
                mText.setText("");
                this.setVisibility(VISIBLE);

        }
    }
}
